#include <Mesh.h>

	/********************************/
	/*			Members				*/
	/********************************/

		/********************************/
		/*			Construcors			*/
		/********************************/
			
			Mesh::Mesh()
			{

			}
			
		/********************************/
		/*			Methods				*/
		/********************************/
		
			void Mesh::AddFace(int a, int b, int c)
			{
				m_Faces.push_back( Face::New(m_Vertices[a], m_Vertices[b], m_Vertices[c]));
			}

			void Mesh::AddVertex(Vertex *vertex)
			{
				m_Vertices.push_back(vertex);
			}
			
            void Mesh::Display()
            {
                Attributes::BindAttribute();

                glDrawElements(GL_TRIANGLES, m_Faces.size()*3, GL_UNSIGNED_SHORT, (void *)+m_Faces[0]->m_Offset);  //Null because we use a IBO
                Attributes::UnbindAttributes();
            }

	/********************************/
	/*			Static				*/
	/********************************/

		/********************************/
		/*			Properties			*/
		/********************************/
		
		/********************************/
		/*			Methods				*/
		/********************************/
			
			Mesh * Mesh::NewTriangle(Vertex *vertex1, Vertex *vertex2, Vertex *vertex3)
			{
				Mesh * mesh = new Mesh;

				mesh->AddVertex(vertex1);
				mesh->AddVertex(vertex2);
				mesh->AddVertex(vertex3);

				mesh->AddFace(0,1,2);

				BufferObject::FeedBuffers();
				
                return mesh;
			}


            Mesh * Mesh::NewRect(float width, float height)
            {
                Mesh * mesh = new Mesh;

                float width_2   =   width/2.0f;
                float height_2  =   height/2.0f;

                printf("Width : %f \n", width_2);
                printf("Height %f \n", height_2);

                mesh->AddVertex(  Vertex::New(

                                                new vec4( -width_2, height_2, -2.0,1.0),
                                                new vec4( 1.0, 0.0, 0.0,1.0),
                                                new vec4( 1.0, 0.0, 0.0,1.0),
                                                new vec4( 0.0, 0.0, 0.0,0.0)

                                            )
                                 );

                mesh->AddVertex(Vertex::New
                                            (
                                                new vec4( width_2, height_2, -2.0,1.0),
                                                new vec4( 1.0, 0.0, 0.0,1.0),
                                                new vec4( 1.0, 0.0, 0.0,1.0),
                                                new vec4( 1.0, 0.0, 0.0,0.0)
                                            )
                                );

                mesh->AddVertex(Vertex::New
                                (
                                    new vec4( width_2, -height_2, -2.0,1.0),
                                    new vec4( 1.0, 0.0, 0.0,1.0),
                                    new vec4( 1.0, 0.0, 0.0,1.0),
                                    new vec4( 1.0, 1.0, 0.0,0.0)
                                ));

                mesh->AddVertex(Vertex::New
                                (
                                    new vec4( -width_2, -height_2, -2.0,1.0),
                                    new vec4( 1.0, 0.0, 0.0,1.0),
                                    new vec4( 1.0, 0.0, 0.0,1.0),
                                    new vec4( 0.0, 1.0, 0.0,0.0)
                                ));

                mesh->AddFace(0,1,2);
                mesh->AddFace(2,0,3);

                BufferObject::FeedBuffers();

                return mesh;
            }


		




